package com.ai3d.rfid.common.event

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.lang.reflect.Type


/**
 * @ProjectName : Trias
 * @Author : weijinsong
 * @Time : 2023/5/20 15:17
 * @Description : 文件描述
 */
object JsonToBeanUtils {
    inline fun <reified T> Gson.fromJson2(json: String, type: Type): T? {
        return if (json.isEmpty()) {
            null
        } else {
            fromJson(json, type)
        }
    }

    inline fun <reified T> toBean(json: String): T? {
        val typeT = object : TypeToken<T>() {}.type
        return Gson().fromJson2<T>(json, typeT)
    }

}